/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.sadhar.sipp.perekamanpospendapatanunit;

import java.util.Map;
import org.sadhar.sia.framework.ClassApplicationModule;
import org.zkoss.zul.Label;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.Textbox;
import org.zkoss.zul.Window;

/**
 *
 * @author kris
 */
public class PerekamanPosPendapatanUnitPopupWnd extends ClassApplicationModule {

    private Listbox lstboxPosPendapatan;
    private PerekamanPosPendapatanUnitDAO posPendapatanUnitDAO;
    private Window window;
    private Textbox txtboxKeySearch;

    public PerekamanPosPendapatanUnitPopupWnd() {
        posPendapatanUnitDAO = new PerekamanPosPendapatanUnitImpl();
    }

    public void onCreate() throws Exception {
        window = (Window) this.getRoot().getFellow("contentDiv").getFirstChild();        
        lstboxPosPendapatan = (Listbox) getFellow("lstboxPosPendapatan");
        txtboxKeySearch = (Textbox) getFellow("txtboxKeySearch");
        load();
    }

    public  void load() throws Exception {
        int no=1;
        lstboxPosPendapatan.getItems().clear();
        for (Map map : posPendapatanUnitDAO.getPosPendapatan(txtboxKeySearch.getValue())) {
            Listitem item = new Listitem();
            item.setValue(map);
            item.appendChild(new Listcell(no+++""));
            item.appendChild(new Listcell(map.get("posPendapatan").toString()));           
            lstboxPosPendapatan.appendChild(item);
        }
    }

    public void lstboxPosPendapataOnSelect(){        
        Map posPendapatan= (Map) lstboxPosPendapatan.getSelectedItem().getValue();       
        Label lblPosPendapatan=(Label) window.getFellow("lblPosPendapatan");
        Textbox txtboxIdPosPendapatan=(Textbox)window.getFellow("txtboxIdPosPendapatan");
        Textbox txtboxSearch=(Textbox)window.getFellow("txtboxSearch");
        lblPosPendapatan.setValue(posPendapatan.get("posPendapatan").toString());
        txtboxIdPosPendapatan.setValue(posPendapatan.get("idPosPendapatan").toString());
        txtboxSearch.setValue(posPendapatan.get("posPendapatan").toString());
        this.detach();
    }
}
